package com.b2b.util.common;


import com.b2b.model.common.CategoryHot;
import com.b2b.service.goodsService.CategoryService;
import com.b2b.util.JedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class StatisticUtil {

    @Autowired
    CategoryService categoryService;

    public static String getOrdersSumKey(Integer sellerId){
        return "ordersNum" + sellerId + TimeUtil.getDateStr();
    }

    public static String getSalesSumKey(Integer sellerId){
        return "SalesSum" + sellerId + TimeUtil.getDateStr();
    }

    public static void updateNumOfOrders(Integer sellerId){
        String key = getOrdersSumKey(sellerId);
        JedisUtil.incInt(key, 1, (long) 1296000);
    }

    public static void updateSalesSum(Integer sellerId, Double price){
        String key = getSalesSumKey(sellerId);
        JedisUtil.incDou(key, price, (long) 1296000);
    }

    public void categoryHot(List<CategoryHot> categoryHotList) {
//        Map<String, Object> categoryHotMap;
//        if(!JedisUtil.exists("categoryHot")) {
//            categoryHotMap = new HashMap<>();
//        }else {
//            categoryHotMap = JSONObject.parseObject(JedisUtil.getJson("categoryHot").replace('=', ':'));
//        }
//        for (CategoryHot c: categoryHotList
//        ) {
//            String categoryName = categoryService.selectByPrimaryKey(c.getCategoryId()).getCategoryName();
//            Integer soldTimes = c.getSoldTimes();
//            if(categoryHotMap != null && categoryHotMap.containsKey(categoryName)){
//                soldTimes += Integer.parseInt(categoryHotMap.get(categoryName).toString());
//            }
//            assert categoryHotMap != null;
//            categoryHotMap.put(categoryName, soldTimes);
//        }
        Map<String, Object> categoryHotMap = new HashMap<>();
    }
}
